﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BL.DataAccess
{
    public class Configuration
    {
        #region Singleton
        private static Configuration s_Current;

        public static Configuration Current
        {
            get
            {
                if (s_Current == null)
                {
                    s_Current = Load();
                    
                    if (s_Current == null)//si sigue siendo null
                    {
                        s_Current = new Configuration();
                        s_Current.Initialize();
                    }
                }
                return s_Current;
            }
        }
        #endregion

        public string DataBasePath { get; set; }
        public string DownloadsDirectory { get; set; }
        private string m_BaseDirectory;

        public string BaseDirectory
        {
            get { return m_BaseDirectory; }
            set { m_BaseDirectory = value; Initialize(); }
        }

        private void Initialize()
        {
            // BaseDirectory = @"I:\Andres\MMExportImport\MultipleSourcesSearch\MultiSourceSearch\MultiSourceSearch\";
            //BaseDirectory = @"C:\Inetpub\wwwroot\MultiSearch\";
            DataBasePath = AppDomain.CurrentDomain.BaseDirectory + @"bd.mdb";           
         
        }

        public Configuration()
        {

        }
        public static Configuration Load()
        {
            return Serializer.Open<Configuration>(AppDomain.CurrentDomain.BaseDirectory + "Config.xml");
        }
               
        public void Save()
        {
            Serializer.Save(this, AppDomain.CurrentDomain.BaseDirectory + "Config.xml");
        }
    }
}
